<?php

namespace common\entities\common;

use common\entities\ConfigEntity;
use Yii;

/**
 * This is the model class for table "myscrm_revenue_recognition_date".
 *
 * @property string $recognition_date_id
 * @property string $recognition_begin
 * @property string $recognition_end
 * @property string $recognition_date
 * @property string $set_by
 * @property string $seter_guid
 * @property string $created_by
 * @property string $created_on
 * @property string $modified_by
 * @property string $modified_on
 * @property integer $is_del
 */
class MyscrmRevenueRecognitionDateEntity extends ConfigEntity
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'myscrm_revenue_recognition_date';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['recognition_date_id'], 'required'],
            [['created_on', 'modified_on'], 'safe'],
            [['is_del'],'integer'],
            [['recognition_date_id','created_by', 'modified_by'], 'string', 'max' => 36],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'recognition_date_id' => '结转期ID',
            'recognition_begin' => '结转期开始时间',
            'recognition_end' => '结转期结束时间',
            'recognition_date' => '确认时间',
            'set_by' => '设置人',
            'seter_guid' => '设置人GUID',
            'created_by' => '创建人',
            'created_on' => '创建时间',
            'modified_by' => '修改人',
            'modified_on' => '修改时间',
            'is_del' => '1:未删除;2:已删除',
        ];
    }
    
    /**
    * 获取当前确认日期&上期确认日期
    * @return array
    */
	public static function getRecognitionDate()
    {
		return self::find()->asArray()->where(['is_del'=>1])->offset(0)->limit(2)->orderBy(['recognition_end' => SORT_DESC])->all();
	}

    /**
     * 获取当前确认日期&上期确认日期
     * @return array
     */
    public static function getRecognitionDateNew()
    {
        return self::find()->asArray()->where(['is_del'=>1])->orderBy(['created_on' => SORT_DESC])->one();
    }

    public static function getRecognitionListDate()
    {
        return self::find()->asArray()->where(['is_del'=>1])->orderBy(['created_on' => SORT_ASC])->all();
    }

    /**
     * 获取所有租期列表
     * @return array
     */
    public static function getRecognitionDateAll()
    {
        return self::find()->asArray()->where(['is_del'=>1])->offset(0)->limit(2)->orderBy(['recognition_end' => SORT_DESC])->all();
    }

    public static function getRecognitionListDateByTime($recognitionBegin,$recognitionEnd)
    {
        return self::find()->asArray()->where(['=' , 'is_del' , 1])->andFilterWhere(
            ['and' ,
                ['>=' , 'recognition_date' , $recognitionBegin],
                ['<=' , 'recognition_date' , $recognitionEnd],
            ])->all();
    }

}
